package com.luisliuyi.demo.optimize.network;

public class NetUtil {
    private ConnectionPool connectionPool;
    public NetUtil() {
        connectionPool = new ConnectionPool();
    }

    public String call(Request request) {
        HttpConnection httpConnection= connectionPool.getHttpConnection(request.getHttpUrl().getHost(),
                request.getHttpUrl().getPort());
        httpConnection.setHttpUrl(request.getHttpUrl());
        String body = httpConnection.call(request);
        //服务器 复用
        if (httpConnection.isKeepAlive()) {
            connectionPool.putHttpConnection(httpConnection);
        } else {
            httpConnection.close();
        }
        return body;
    }
}
